export const strZip = (str: string) => {
    let result = ''
    let re = str.match(/(a+|b+|c+|d+|e+|f+|g+|h+|i+|j+|k+|l+|m+|n+|o+|p+|q+|r+|s+|t+|u+|v+|w+|x+|y+|z+)/g)
    if (re) re.forEach(item => result += item[0] + item.length)
    return result
}
export const strZip2 = (str: string) => {
    let result = str.replace(/(a+|b+|c+|d+|e+|f+|g+|h+|i+|j+|k+|l+|m+|n+|o+|p+|q+|r+|s+|t+|u+|v+|w+|x+|y+|z+)/g, (...args) => {
        if (args[2] === 0) {
            console.log(args);
        }

        return args[0][0] + args[0].length
    })
    return result
}
/**
 * 格式化日期或事件
 * @param date 日期或者时间
 * @param formmat 格式化模板
 * @returns 返回根据模板转化后的字符串
 */
export const formmatTime = (date: string | Date, formmat: string) => {
    let d = new Date(date)
    const timeObj: { [key: string]: number } = {
        y: d.getFullYear(),
        M: d.getMonth() + 1,
        d: d.getDate(),
        h: d.getHours(),
        m: d.getMinutes(),
        s: d.getSeconds(),
        S: d.getMilliseconds()
    }
    const reg = /(y+|M+|d+|h+|m+|s+|S+)/g
    return formmat.replace(reg, (item) => {
        return timeObj[item.slice(-1)].toString().padStart(item.length, '0')
    })
}